package c.c.b.a.a.a;

import android.annotation.TargetApi;
import android.content.BroadcastReceiver;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Pair;
import c.c.c.b;

public abstract class b extends BroadcastReceiver {

    public interface a {
        int a();
    }

    @TargetApi(11)
    /* renamed from: c.c.b.a.a.a.b$b  reason: collision with other inner class name */
    static final class C0093b implements Handler.Callback {
        private C0093b() {
        }

        /* synthetic */ C0093b(byte b2) {
            this();
        }

        /* JADX INFO: finally extract failed */
        public final boolean handleMessage(Message message) {
            c.c.a.a.c(message, "msg");
            if (message.what == 0) {
                c.c.a.a.c(message.obj, "msg.obj");
                boolean z = false;
                c.c.a.a.a(message.arg1, 0, 1, "msg.arg1");
                Pair pair = (Pair) message.obj;
                if (message.arg1 != 0) {
                    z = true;
                }
                BroadcastReceiver.PendingResult pendingResult = (BroadcastReceiver.PendingResult) pair.first;
                try {
                    int a2 = ((a) pair.second).a();
                    if (z) {
                        pendingResult.setResultCode(a2);
                    }
                    pendingResult.finish();
                    if (c.c.c.a.a(18)) {
                        Looper.myLooper().quitSafely();
                    } else {
                        Looper.myLooper().quit();
                    }
                } catch (Throwable th) {
                    pendingResult.finish();
                    throw th;
                }
            }
            return true;
        }
    }

    protected b() {
    }

    /* access modifiers changed from: protected */
    @TargetApi(11)
    public final void a(a aVar, boolean z) {
        c.c.a.a.c(aVar, "callback");
        BroadcastReceiver.PendingResult goAsync = goAsync();
        if (goAsync != null) {
            Handler handler = new Handler(c.c.c.b.a(getClass().getName(), b.a.BACKGROUND).getLooper(), new C0093b((byte) 0));
            if (!handler.sendMessage(handler.obtainMessage(0, z ? 1 : 0, 0, new Pair(goAsync, aVar)))) {
                throw new AssertionError();
            }
            return;
        }
        throw new AssertionError("PendingResult was null.  Was goAsync() called previously?");
    }
}
